<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>迭代器</title>
</head>
<body>
    <script>
        // 实现迭代器
        function each(obj, callback, context, arg) {
            /**
             * for 循环遍历obj 
             */ 
            var i = 0,
                length = obj.length,
                value;
            for (; i < length; i++) {
                value = callback.call(context || null, obj[i], i, obj, arg)
                if(value === false) {
                    break;
                }
            }
        }

        // test
        var arr = ['a', 'b', 'c']
        each(arr, function(item, index, arr) {
            console.log('item :>> ', item)
            console.log('index :>> ', index);
            console.log('arr :>> ', arr);
        }, this, 'aaa')
    </script>
</body>
</html>